	function clsMyCardRecordInout(){
		this.idx = null;
		this._HTMLDom = null;
		this._init();	
	}
	
	clsMyCardRecordInout.prototype = {
		_init: function(){
			var $layer = $("section#my_card_record>section>div.my_card_tab a")
			this._HTMLDom = {
				"$layer": $layer	
				, "$view": $("section#my_card_record>section>div.my_card_record")
			}	
		}
		, setIdx: function(n){
			if(this.idx==n) return;
			this.idx = n;
			this._HTMLDom["$view"].hide().eq(n).show();
			this._HTMLDom["$layer"].removeClass("ui-btn-active").eq(n).addClass("ui-btn-active");
		}
		, $getTab: function(){			
			return this._HTMLDom["$layer"];	
		}		
	}

	//스코어카드-OUT
	function clsMyCardRecordOut(objControl){
		this.listData = null;		
		this.objC = objControl;		
		this.round_type = null;
		this._HTMLDom = null;
		this._init();
	}
	
	clsMyCardRecordOut.prototype = {
		_init: function(){
			var $layer = $("section#my_card_record>section>div.my_card_record:eq(0)");			
			this._HTMLDom = {
				"$layer": $layer	
				, "$element": $layer.find("tbody tr:first")
				, "$select": $layer.find("tbody tr:first>td:eq(2)")				
			}
			$layer.find("tfoot tr td:eq(0)").html("OUT소계");
			$layer.find("tbody").empty();
			
			this._bind();
		}
		, setList: function(thisData, round_type){
			this.round_type = round_type;
			this.listData = thisData;	
			this.display();
		}
		, display:function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var selectOption = $element.find("select").get(0).outerHTML;
			var thisClass = this;
			
			$layer.find("tbody").empty();
			
			for(var i=0;i<9;++i){				
				$layer.find("tbody").append($element.clone(true));
			}
			
			//직접입력 유무
			var b = (this.round_type!= 0?true:false);
			
			for(var i=0;i<9;++i){
				var $tmp = $layer.find("tbody tr").eq(i);
				$tmp.find("td:eq(0)").html(i+1);
				$tmp.find("td:eq(1) input").val(0);
				$tmp.find("td:eq(2)").empty().html(selectOption).find("select").selectmenu();	
				
				if(this.listData.length > i){			
					if(b){
						$tmp.find("td:eq(1)").html(this.listData[i]["파"]);
					}else {
						$tmp.find("td:eq(1) input").val(this.listData[i]["파"]);
					}
					$tmp.find("select option").eq(this.listData[i]["증감치"]).prop("selected",true);										
				}	
				$tmp.find("select").selectmenu("refresh");											
				this.changeSum(i);
			}
			
		}
		, $getSelect: function(){
			return this._HMTLDom["$layer"].find("select");	
		}
		, reset: function(){				
			var $layer = this._HTMLDom["$layer"];
			var thisClass = this;
			$layer.find("tbody tr").each(function(n){
				$layer.find("tbody tr td:nth-child(2) input").eq(n).val(0);
				$(this).find("select option:eq(0)").prop("selected",true);
				$(this).find("select").selectmenu("refresh");
			
				thisClass.changeSum(n);
			});
		}
		, changeSum:function(n){
			//직접입력 유무
			var b = (this.round_type!= 0?true:false);			
			
			var $layer = this._HTMLDom["$layer"];
			var _par = null;
			if(b){
				_par = $layer.find("tbody tr td:nth-child(2)");				
			}else {
			 	_par = $layer.find("tbody tr td:nth-child(2) input");
			}
			var _select = $layer.find("select");
			var _select_v = 0;
			var _score = $layer.find("tbody tr td:nth-child(4)");

			var _parSum = $layer.find("tfoot tr:eq(0) td:eq(1)");
			var _selectSum = $layer.find("tfoot tr:eq(0) td:eq(2)");
			var _scoreSum = $layer.find("tfoot tr:eq(0) td:eq(3)");
			
			//행계산
			if(!Number(_select.eq(n).find("option:selected").html())){
				_select_v = 0;
			}else {
				_select_v = _select.eq(n).find("option:selected").html();
			}
			
			if(b){
				if(!Number(_par.eq(n).html())) _par.eq(n).html(0);
				_score.eq(n).html(Number(_select_v) + Number(_par.eq(n).html()));
			}else {
				if(!Number(_par.eq(n).val())) _par.eq(n).val(0);
				_score.eq(n).html(Number(_select_v) + Number(_par.eq(n).val()));
				_par.eq(n).val(Number(_par.eq(n).val()));
			}
			
			var tmp1 = 0;	
			var tmp2 = 0;
			var tmp3 = 0;			
			
			//소계계산
			for(var i=0;i<_par.length;++i){
				//파합계
				if(b){
					if(Number(_par.eq(i).html())) tmp1 += Number(_par.eq(i).html());
				}else{				
					if(Number(_par.eq(i).val())) tmp1 += Number(_par.eq(i).val());
				}
				//+/-합계
				if(Number(_select.eq(i).find("option:selected").html())) tmp2 += Number(Number(_select.eq(i).find("option:selected").html()));				
				//스코어합계
				if(Number(_score.eq(i).html())) tmp3 += Number(_score.eq(i).html());
			}
			
			_parSum.html(tmp1);
			_selectSum.html(tmp2);
			_scoreSum.html(tmp3);
			
			this.objC.changeTSum();
			//$(this).trigger("changeTSum");
		}
		, _bind: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			
			//셀렉트박스 변경이벤트
			$layer.on("change","select",function(event){
				var n = $layer.find("select").index($(this));
				thisClass.changeSum(n);
			});
			
			//파정보 변경 이벤트
			$layer.on("keyup", "input", function(event){
				var n = $layer.find("tbody tr input").index($(this));			
				thisClass.changeSum(n);
			});
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];	
		}
		, getSummery: function(){
			var $layer = this._HTMLDom["$layer"];
			var _parSum = $layer.find("tfoot tr:eq(0) td:eq(1)");
			var _selectSum = $layer.find("tfoot tr:eq(0) td:eq(2)");
			var _scoreSum = $layer.find("tfoot tr:eq(0) td:eq(3)");
			var result = {
				"파": _parSum.html()
				, "증감치": _selectSum.html()
				, "스코어":_scoreSum.html()
			}
			return result;
		}
		, setSummery: function(resIn){
			var $layer = this._HTMLDom["$layer"];
			var resOut = this.getSummery();
			
			var _parTSum = $layer.find("tfoot tr:eq(1) td:eq(1)");
			var _selectTSum = $layer.find("tfoot tr:eq(1) td:eq(2)");
			var _scoreTSum = $layer.find("tfoot tr:eq(1) td:eq(3)");
			
			_parTSum.html(Number(resOut["파"]) + Number(resIn["파"]));
			_selectTSum.html(Number(resOut["증감치"]) + Number(resIn["증감치"]));
			_scoreTSum.html(Number(resOut["스코어"]) + Number(resIn["스코어"]));
		}
		, getValue: function(){
			//직접입력 유무
			var b = (this.round_type!= 0?true:false);
			
			var result = [];
			var $layer = this._HTMLDom["$layer"];			
			var _par = null;
			
			if(b){
				_par = $layer.find("tbody tr td:nth-child(2)");
			}else {
				_par = $layer.find("tbody tr td:nth-child(2) input");
			}
			var _select = $layer.find("select");
			var _score = $layer.find("tbody tr td:nth-child(4)");
			
			for(var i=0;i<_par.length;++i){			
				var par = 0;
				if(b){
					par = _par.eq(i).html();
				}else{
					par = _par.eq(i).val();
				}
				result.push({
					"파": _par.eq(i).val()
					, "증감치": _select.eq(i).find("option").index(_select.eq(i).find("option:selected"))
					, "스코어": _score.eq(i).html()
				});	
			}
			
			return result;
		}
		, getScoreTSum: function(){
			var $layer = this._HTMLDom["$layer"];						
			return $layer.find("tfoot tr:eq(1) td:eq(3)").html();
		}
	}
	
	//스코어카드-IN
	function clsMyCardRecordIn(objControl){
		this.listData = null;		
		this.objC=objControl;
		this.round_type = null;
		this._HTMLDom = null;
		this._init();
	}
	
	clsMyCardRecordIn.prototype = {
		_init: function(){
			var $layer = $("section#my_card_record>section>div.my_card_record:eq(1)");			
			this._HTMLDom = {
				"$layer": $layer	
				, "$element": $layer.find("tbody tr:first")
				, "$select": $layer.find("tbody tr:first>td:eq(2)")				
			}
			
			$layer.find("tfoot tr td:eq(0)").html("IN소계");
			$layer.find("tbody").empty();
			
			this._bind();
		}
		, setList: clsMyCardRecordOut.prototype.setList
		, display: clsMyCardRecordOut.prototype.display
		, $getSelect: clsMyCardRecordOut.prototype.$getSelect
		, reset:clsMyCardRecordOut.prototype.reset
		, changeSum: clsMyCardRecordOut.prototype.changeSum
		, _bind: clsMyCardRecordOut.prototype._bind
		, $getLayer: clsMyCardRecordOut.prototype.$getLayer
		, getSummery: clsMyCardRecordOut.prototype.getSummery
		, setSummery: clsMyCardRecordOut.prototype.setSummery
		, getValue: clsMyCardRecordOut.prototype.getValue
	}
	
	//데이터연동		
	function clsComm_MyCardRecord(){
		this.scoreList = null;
		this.scoreListRequest = null;
		
		this._init();
	}
		
	clsComm_MyCardRecord.prototype = {
		_init: function(){
			this.scoreListRequest = {
				"라운드키": null
			}	
		}
//------------------------ 스코어카드목록------------------------//		
		, getScoreList: function(){
			var thisClass = this;
						
			var szReservSeq = this.scoreListRequest["예약코드"];		
			
			var objJson = new MJson();
        	var cm = new ConnectionManager();

			objJson.putClient("userid", "golfin3");
        	objJson.putPub("sid", "US001");
        	objJson.putPub("servicename", "getMyScoreCard");
        		
        	objJson.putParameter("reservSeq", szReservSeq);
        
        	cm.requestGet(objJson.getJsonString(), function(ret){
				thisClass.scoreList = [];
				
				var items = ret["msp"]["contents"]["items"];
				if(items){					
					
					if(!items.length) items = new Array(items);
					var _parTSum = 0;
					var _calTSum = 0;
					var _scoreTSum = 0;
					
					var hole = items[0]["holeCnt1"] + items[1]["holeCnt2"];
					
					for(var i=0;i<hole;++i){
						
					}
					
				}
				$(thisClass).trigger("evtFinishScoreList");
			}, function($err) {
				alert($err);
			});				
		}
		, getScoreListData: function(){
			return this.scoreList;	
		}
		, setScoreListDataRequest: function(key,val){
			return this.scoreListRequest[key]=val;	
		}
//------------------------ 스코어카드목록------------------------//		
	}
	
	//컨트롤파일
	function MyCardRecord(){	
		this.objScore = null;
		this.reserv_seq = null;
		this.round_type = null;
		this.inout_idx = 0;
		
		this.objComm = null;					
		this.objMyCardRecordIn = null;
		this.objMyCardRecordOut = null;
		this.objMyCardRecordInout = null;
	};
	
	MyCardRecord.prototype = {
	    onPageShow : function() {
	    	$("a").attr("href", "").attr("data-rel", "");
	    	$("section#my_card_record>section>div.my_card_record").before($("section#my_card_record>section>div.my_card_record").get(0).outerHTML);
	    	
	    	this._init();	    	
	    }
	   , _init: function(){
	      	this.objComm = new clsComm_MyCardRecord();
	      	this.objMyCardRecordIn = new clsMyCardRecordIn(this);
	      	this.objMyCardRecordOut = new clsMyCardRecordOut(this);
	      	this.objMyCardRecordInout = new clsMyCardRecordInout();
	      	
	      	this._role();

	      	this.getParam();
	      	
	      	this._bind();
	    }
	    , _start: function(){
	    	this.spinStart(); 
	     	this.objComm.setScoreListDataRequest("예약코드", this.reserv_seq);
	      	this.objComm.getScoreList();
	      	this.objMyCardRecordInout.setIdx(0);
	    }
	    , _bind: function(){
			var thisClass = this;
			
			//스코어정보 조회 완료이벤트			
			$(this.objComm).bind("evtFinishScoreList", function(event){
				var thisData = thisClass.objComm.getScoreListData();
				thisClass.objMyCardRecordIn.setList(thisData, thisClass.round_type);
				thisClass.objMyCardRecordOut.setList(thisData, thisClass.round_type);
			});
			
			// in/out코스탭 이벤트
			this.objMyCardRecordInout.$getTab().click(function(event){				
				var idx = thisClass.objMyCardRecordInout.$getTab().index($(this));				
				thisClass.objMyCardRecordInout.setIdx(idx);
			});			
			
			//초기화 이벤트
			$("section#my_card_record footer.my_card_bt div.btn_area02 div a:eq(0)").click(function(event){
				thisClass.objMyCardRecordIn.reset();
				thisClass.objMyCardRecordOut.reset();
			});
			
			//작성완료 이벤트
			$("section#my_card_record footer.my_card_bt div.btn_area02 div a:eq(1)").click(function(event){
				//<--초기화
		 		if(!_gf.MYPAGE_DATA) {
			 		_gf.MYPAGE_DATA  = {}
			 	}
			 	
		 		_gf.MYPAGE_DATA["스코어카드"] = {
		 			"스코어카드수": thisClass.objMyCardRecordOut.getScoreTSum()
		 			, "아웃코스": thisClass.objMyCardRecordOut.getValue()
		 			, "인코스": thisClass.objMyCardRecordIn.getValue()
		 		}
			 	//초기화-->
			 	var _url = _gf.MYPAGE_DATA["리턴페이지"];
				$.mobile.changePage(_url,"slide",true);
			});
			/*
			//코스합계
			$(this.objMyCardRecordOut).bind("changeTSum", function(event){
				alert("바인드");
				thisClass.changeTSum();
			});
			$(this.objMyCardRecordIn).bind("changeTSum", function(event){
				thisClass.changeTSum();
			});
			*/
			//메뉴
			$("section#my_card_record nav ul li a:eq(0)").click(function(event){
				event.preventDefault();
				$.mobile.changePage( "../inc/navi.html","slide",true);	
			});
			
			//알림
			$("section#my_card_record nav ul li:eq(1)").click(function(event){
				event.preventDefault();
				$.mobile.changePage("../inc/info_booking.html","slide",true);	
			});
		}  
		, spinStart: function(){		
			$.mobile.showPageLoadingMsg();			
		}
		, spinEnd: function(){			
	 		$.mobile.hidePageLoadingMsg();				
		} 
		, _role: function(){
	    		if(!_util.getLogin("로그인")){
	    			//alert("로그인 후 이용하실 수 있습니다.");		    			
	    			this.goNavi();		
	    			return;
	    		}
	   }
		, goNavi: function(){			
			$.mobile.changePage("../inc/navi.html","slide",true);
		}
		, getParam: function(key){		 	
	    	this.reserv_seq = _gf.MYPAGE_DATA["예약코드"];
	    	this.round_type = _gf.MYPAGE_DATA["라운드구분"];
	    	
	    	if(_gf.MYPAGE_DATA["스코어카드"]){
	    		this.objMyCardRecordIn.setList(_gf.MYPAGE_DATA["스코어카드"]["인코스"], this.round_type);
				this.objMyCardRecordOut.setList(_gf.MYPAGE_DATA["스코어카드"]["아웃코스"], this.round_type);
				this.objMyCardRecordInout.setIdx(0);
	    	}else {
				this._start();
	    	}
	    }
		//코스합계
		, changeTSum: function(){
			if(!this.objMyCardRecordOut) return;
			
			var outSum = this.objMyCardRecordOut.getSummery();
			var inSum = this.objMyCardRecordIn.getSummery();
			
			this.objMyCardRecordOut.setSummery(inSum);
			this.objMyCardRecordIn.setSummery(outSum);
		
		}
	}
	